import game.game
import render.textrenderer
import events.dispatcher
import pygame
import window.window
import game.entity
import game.gameworld

class DemoBoid( game.entity.Boid):
    def draw(self):
        super( DemoBoid, self ).draw()
        render.textrenderer.instance().render(
        "Mass: %.0f Max Speed: %.2f Max Force: %.2f Max Turn: %.2f Curr Speed: %.2f"
        %( self.mass, self.maxSpeed, self.maxForce, self.maxTurnRate, self.velocity.magnitude() ),
        ( 100, 10 ), (0, 0, 0) )

class Point( game.entity.StaticEntiy ):
    def __init__( self, window, pos ):
        super( Point, self ).__init__( window, pos )
        self.pt = self.transform * self.pos
        self.radius = 3
        self.colour = ( 255, 0, 0 )

    def draw( self ):
        pygame.gfxdraw.filled_circle( self.window.screen, int(self.pt.x), int(self.pt.y), self.radius, self.colour )

class BaseGame( game.game.Game ):
    """
    Base class for creating a small demo
    Handles basic key handling and rendering of standard info and the background
    """

    MOUSE_LEFT = 1
    MOUSE_MIDDLE = 2
    MOUSE_RIGHT = 3

    def __init__(self):
        super(BaseGame, self).__init__( )


    def setup(self):
        super( BaseGame, self ).setup()
        events.dispatcher.instance().register( events.dispatcher.PyGameKeyUp, self._onKey )
        self.window = window.window.Window( 700, 700, "PyAI Demo" )

        #Create a background, the same size as the screen
        self.background = pygame.Surface( self.window.screen.get_size() )
        self.background.convert()
        self.background.fill( (255, 255, 255) )

        render.textrenderer.instance().setup( self.window, 18 )
        

    def _preRender(self):
        super(BaseGame, self)._preRender()
        self.window.screen.blit( self.background, (0,0) )
        render.textrenderer.instance().render( "FPS: %.2f" %(self.clock.get_fps()), ( 10, 10 ), ( 0, 0, 0 ) )

    def _onKey(self, event):
        if event.key == pygame.K_SPACE:
            self.paused = not self.paused
        
        